<!doctype html>
<html class="x-admin-sm" style="font-size: 100px !important;height: 100%">
    <head>
        <include file="Manage/themes/default/meta" />
        <script type="text/javascript" src="{{$__COMMON__}}/js/iscroll.js?v={{$static_version}}"></script>
        <style>
            body{
                background: #EFF2FA;
            }
        </style>
    </head>
    <body class="index">
        <!-- 顶部开始 -->
        <div class="container layui-bg-blue">
            <div class="container-left logo">
                <a href="javascript:void(0);">总管理平台</a>
            </div>

            <div class="container-center">
                <ul id='top-menue'></ul>
            </div>

            <ul class="layui-nav layui-bg-blue right" lay-bar="disabled">
                <li class="layui-nav-item">
                    <a href="javascript:void(0);">
                        <img src="{{$__STATIC__}}/images/face.jpg" class="layui-nav-img">{{$admin['nickname']}}
                    </a>
                    <dl class="layui-nav-child">
                        <dd><a href="javascript:void(0);" onclick="Pages.openEditPwdWindow()">修改密码</a></dd>
                        <dd><a href="javascript:void(0);" onclick="Pages.loginOut()">退出登录</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item" lay-unselect>
                    <a href="javascript:void(0);">消息<span class="layui-badge">9</span></a>
                </li>
                <li class="layui-nav-item" lay-unselect>
                    <a href="javascript:void(0);">控制台<span class="layui-badge-dot"></span></a>
                </li>
            </ul>
        </div>
        <!-- 顶部结束 -->

        <!-- 中部开始 -->
        <!-- 左侧菜单开始 -->
        <div class="left-nav open">
            <div id="side-nav">
                <div class="nav-title"></div>
                <div id="nav-content">
                    <ul id="nav"></ul>
                </div>
            </div>
        </div>
        <!-- 左侧菜单结束 -->
        <!-- 右侧主体开始 -->
        <div class="page-content">
            <div class="layui-tab tab" lay-filter="xbs_tab" lay-allowclose="false">
                <div class="left_btn" >
                    <i title="展开左侧栏" class="iconfont layui-icon" >&#xe668;</i>
                </div>
                <ul class="layui-tab-title">
                    <li class="home">
                        <i class="layui-icon">&#xe68e;</i>我的桌面
                    </li>
                </ul>
                <div class="layui-unselect layui-form-select layui-form-selected" id="tab_right">
                    <dl>
                        <dd data-type="this">关闭当前</dd>
                        <dd data-type="other">关闭其它</dd>
                        <dd data-type="all">关闭全部</dd>
                    </dl>
                </div>
                <div class="layui-tab-content">
                    <div class="layui-tab-item layui-show">
                        <iframe src='/manage/main' frameborder="0" scrolling="yes" class="x-iframe"></iframe>
                    </div>
                </div>
                <div id="tab_show"></div>
            </div>
        </div>
        <!-- 右侧主体结束 -->
        <!-- 中部结束 -->
    </body>
<script>

    var meneuJosn = '{{:addslashes($menue??'[]')}}';
    var slectMenueId = parseInt({{$slectMenueId??0}});
    var selectTopMenueId = parseInt({{$selectTopMenueId ?? 0}});
    var selectSecondMenueId = parseInt({{$selectSecondMenueId ?? 0}});
    var selectMeneue = "{{$selectMeneue ?? ''}}";

    $(document).ready(function(){
        Pages.init();
        Pages.menueScroll = new IScroll('#nav-content', {
            mouseWheel: true,
            scrollbars: true,
            scrollX:false,
            scrollY:true,
            click:true,
        });
    });

    var Pages = {
        canOperate:true,
        menueList:{},
        menueScroll:'',
        defaultMainUrl:'main',
        authTimer:'',
        nowTab:0,
        init:function(){
            var selectTab = layui.data('manage_top_tab');
            if(selectTab){
                Pages.nowTab = selectTab.top_tab;
            }
            Pages.menueList = JSON.parse(meneuJosn);
            Pages.createTopMenue();
            Pages.initLeftMenue();
        },
        initLeftMenue:function(){
            var tabId = Pages.nowTab;
            if(!tabId){
                tabId = $($("#top-menue").children("li").get(0)).attr('data-id');
            }
            if($('#top-menue li[data-id="'+tabId+'"]').length <=0){
                tabId = $($("#top-menue").children("li").get(0)).attr('data-id');
            }
            if(tabId){
                Pages.selectMenue(tabId);
            }
        },
        createTopMenue:function(){
            var str = '';
            for(var i in Pages.menueList){
                if(selectTopMenueId && i != selectTopMenueId){
                    //continue;
                }
                var clickStr = '';
                if("child" in Pages.menueList[i]){
                    clickStr = 'Pages.selectMenue(\''+i+'\')';
                }else{
                    if(Pages.menueList[i]['url']){
                        clickStr = "openTab('"+Pages.menueList[i]['name']+"','"+Pages.menueList[i]['url']+"')";
                    }
                }
                var activeStr ='';
                if(Pages.menueList[i]['id'] == Pages.nowTab){
                    activeStr = ' class="active"';
                }
                str += '<li class="layui-nav-item" lay-unselect="" data-id="'+i+'">';
                str += '    <a href="javascript:void(0)" onclick="'+clickStr+'"'+activeStr+'>';
                str += Pages.menueList[i]['name'];
                str += '    </a>';
                str += '</li>';
            }
            $('#top-menue').html(str);
            var topScroll = new IScroll('.container-center', {
                mouseWheel: true,
                scrollbars: true,
                scrollX:true,
                scrollY:false
            });
        },
        selectMenue:function(id){
            var list = {};
            for(var i in this.menueList){
                if(i == id){
                    list = Pages.menueList[i];
                    break;
                }
            }
            $('#top-menue li').find('a').removeClass('nav-active');
            $('#top-menue li[data-id="'+id+'"]').find('a').addClass('nav-active');
            $('.nav-title').html(list['name']);
            var str = '';
            if('child' in list){
                var childTwo = list['child'];
                for(var i in childTwo){
                    if(!childTwo[i]['name']){
                        continue;
                    }
                    var clickStr = '';
                    var twoIcon = '';
                    var childTwoClass = '';
                    var childTwoIsMenue = 0;
                    var cTabId = '';
                    if('child' in childTwo[i]){
                        clickStr = 'Pages.toggleMenu(this)';
                        twoIcon = '<i class="iconfont nav_right">&#xe6a6;</i>';
                        childTwoClass = ' class="second-nav"';
                    }else{
                        if(childTwo[i]['url']){
                            cTabId = md5(VK.U(childTwo[i]['url']));
                        }
                        if(childTwo[i]['url']){
                            clickStr = "openTabLeft('"+childTwo[i]['name']+"','"+childTwo[i]['url']+"',this)";
                            childTwoIsMenue = 1;
                        }
                    }

                    str+='<li class="open" second-menue_id="'+i+'">';
                    // str+='<a href="javascript:void(0);" right_name="'+childTwo[i]['name']+'" menu_url="'+childTwo[i]['url']+'" is_menue="'+childTwoIsMenue+'" tab-id="'+cTabId+'"  onclick="'+clickStr+'"'+childTwoClass+'>';
                    str+='<a href="javascript:void(0);" right_name="'+childTwo[i]['name']+'" menu_url="'+childTwo[i]['url']+'" is_menue="'+childTwoIsMenue+'" tab-id="'+cTabId+'"  onclick="'+clickStr+'" class="second-nav">';
                    str+='  <cite>'+childTwo[i]['name']+'</cite>';
                    str+=twoIcon;
                    str+='</a>';
                    if('child' in childTwo[i]){
                        var childThree = childTwo[i]['child'];
                        str+='<ul class="sub-menu" style="display:block;">';
                        for(var j in childThree){
                            if(!childThree[j]['name']){
                                continue;
                            }
                            var ccTabId = '';
                            if(childThree[j]['url']){
                                ccTabId = md5(VK.U(childThree[j]['url']));
                            }
                            str+='  <li>';
                            str+='      <a href="javascript:void(0)" right_name="'+childThree[j]['name']+'" menu_url="'+childThree[j]['url']+'" tab-id="'+ccTabId+'" is_menue="1" onclick="openTabLeft(\''+childThree[j]['name']+'\',\''+childThree[j]['url']+'\',this)">';
                            str+='          <cite>'+childThree[j]['name']+'</cite>';
                            str+='      </a>';
                            str+='  </li>';
                        }
                        str+='</ul>';
                    }
                    str+='</li>';
                }
            }
            $('#nav').html(str);
            layui.data('manage_top_tab', {
                key: 'top_tab',
                value: id
            });
            setTimeout(function(){
                Pages.menueScroll.refresh();
            },100);
        },
        toggleMenu:function(obj){
            if($(obj).closest('li').hasClass('open')){
                $(obj).closest('li').removeClass('open');
                $(obj).closest('li').find('ul').css({'display':'none'});
                $(obj).find('i').html('&#xe697;');
            }else{
                $(obj).closest('li').addClass('open');
                $(obj).closest('li').find('ul').css({'display':'block'});
                $(obj).find('i').html('&#xe6a6;');
            }
            Pages.menueScroll.refresh();
        },
        openEditPwdWindow:function(){
            VK.openPoerWindow('修改密码', VK.U('password'), 0,600, 400);
        },
        loginOut:function(){
            if(!Pages.canOperate){
                return false;
            }
            var loading = VK.load();
            Pages.canOperate = false;
            VK.QAjax(VK.U('login'), 'delete',{},function(res){
                VK.closeLoad(loading);
                if(res.status!==200){
                    Pages.canOperate = true;
                    VK.error(res.msg);
                    return false;
                }
                window.location.href= VK.U('login');
            },function(res){
                VK.closeLoad(loading);
                Pages.canOperate = true;
                VK.error('系统出错稍后再试');
            });
        }
    }
    function openTab(title,url){
        var u = VK.U(url);
        xadmin.add_tab(title,u);
    }

    function openTabLeft(title,url,obj){
        var u = VK.U(url);
        xadmin.add_tab(title,u);
    }
</script>
</html>
